<template>
  <h1>vue2响应式原理</h1>
  <h1>姓名: {{ person.name }}</h1>
  <h1>年龄: {{ person.age }}</h1>
  <h1 v-show="person.sex">性别: {{ person.sex }}</h1>
  <h1>爱好: {{ person.hobby }}</h1>
  <button @click="addSex">添加一个sex属性</button>
  <button @click="deleteName">删除name属性</button>
  <button @click="updateHobby">修改第一个爱好的名字</button>
</template>

<script>
import Vue from 'vue'
export default {
  name: "App",
  data() {
    return {
      person: {
        name: "张三",
        age: 18,
        hobby: ['学习','吃饭']
      }
    }
  },
  methods: {
    addSex() {
      console.log(this)
      // this.$set(this.person, "sex", "女")
      Vue.set(this.person, "sex", "女")
    },
    deleteName() {
      // this.delete(this.person,'name')
      Vue.delete(this.person,'name', '女')
    },
    updateHobby() {
      // this.$set(this.person.hobby,0,'逛街')
      this.person.hobby.splice(0,1,'逛街')
    }
  },
}
</script>

